package cn.tedu.boot41.controller;


import cn.tedu.boot41.entity.Product;
import cn.tedu.boot41.mapper.ProductMapper;
import org.apache.tomcat.util.net.jsse.JSSEUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductController {

    @Autowired(required = false)
    private ProductMapper productMapper;

    @RequestMapping("/insert")
    public void insert(@RequestBody Product product){
        System.out.println(product);
        productMapper.insert(product);
    }

    @RequestMapping("/delete")
    public void delete(int id){
        productMapper.deleteById(id);
    }

    @RequestMapping("/update")
    public void update(@RequestBody Product product){
        productMapper.updateProduct(product);
    }

    @RequestMapping("/selectAll")
    public List<Product> selectAll(){
        List<Product> list = productMapper.selectAllProducts();
        System.out.println("---------"+list);
        return list;
    }
    @RequestMapping("/selectById")
    public  Product select(int id){
        Product product = productMapper.selectProductById(id);
        return product;
    }

}
